<?php
/* @var $this CatalogItemController */
/* @var $model CatalogItem */
/* @var $form CActiveForm */
CHtml::$errorContainerTag = 'span';
?>

<div class="form" ng-app="picturesEditor">

	<?php $form=$this->beginWidget('CActiveForm', array(
		'id'=>'catalog-item-form',
	// Please note: When you enable ajax validation, make sure the corresponding
	// controller action is handling ajax validation correctly.
	// There is a call to performAjaxValidation() commented in generated controller code.
	// See class documentation of CActiveForm for details on this.
		'enableClientValidation'=>true,
	'clientOptions'=>array(
		'validateOnSubmit'=>true,
	),
	'errorMessageCssClass'=>'error',
		'htmlOptions' => array(
			'enctype' => 'multipart/form-data',
			),
			)); ?>

			<p class="note">Fields with <span class="required">*</span> are required.</p>

			<?php echo $form->errorSummary($model); ?>

			<div class="row">
				<div class="large-12 columns">
			<label>
				<?php echo $form->labelEx($model,'title'); ?>
				<?php echo $form->textField($model,'title',array('size'=>60,'maxlength'=>100)); ?>
			</label>
				<?php echo $form->error($model,'title'); ?>
			</div>
			</div>

			<div class="row">
				<div class="large-12 columns">
			<label>
				<?php echo $form->labelEx($model,'description'); ?>
				<?php echo $form->textArea($model,'description',array('rows'=>6, 'cols'=>50)); ?>
				</label>
				<?php echo $form->error($model,'description'); ?>
				</div>
			</div>

			<div class="row">
				<div class="large-12 columns">
			<label>
				<?php echo $form->labelEx($model,'code'); ?>
				<?php echo $form->textField($model,'code',array('size'=>60,'maxlength'=>100)); ?>
				</label>
				<?php echo $form->error($model,'code'); ?>
				</div>
			</div>

			<div class="row">
				<div class="large-12 columns">
					<select name="CatalogItem[type]">
						<option value="<?php echo ConstProductType::CatalogItem; ?>" <?php if($model->type==ConstProductType::CatalogItem) echo 'selected'; ?> >Catalog Item</option>
						<option value="<?php echo ConstProductType::News; ?>" <?php if($model->type==ConstProductType::News) echo 'selected'; ?> >News</option>
					</select>
				</div>
			</div>

			<div class="row">
				<div class="large-12 columns">
					<select name="CatalogItem[state]">
						<option value="<?php echo ConstProductState::Draft; ?>" <?php if($model->state==ConstProductState::Draft) echo 'selected'; ?> >Draft</option>
						<option value="<?php echo ConstProductState::Publicated; ?>" <?php if($model->state==ConstProductState::Publicated) echo 'selected'; ?> >Publicated</option>
					</select>
				</div>
			</div>

			<div class="row">
				<div class="large-12 columns">
					<input name="CatalogItem[view_count]" id="CatalogItem_view_count" type="hidden" value="0">
				</div>
			</div>

			<div class="row">
				<div class="large-12 columns">
					<select name="CatalogItem[catalog_id]">
						<option value="">---</option>
						<?php
						$catalogs = Catalog::model()->findAll();
						$selected = '';
						foreach ($catalogs as &$catalog) {
							if($catalog->id == $model->catalog_id){
								$selected = 'selected';
							}else{
								$selected = '';
							}
							echo '<option '.$selected.' value="'.$catalog->id.'">'.$catalog->title.'</option>';
						}
						?>
					</select>
				</div>
			</div>

			<div class="row">
				<input type="hidden" value="<?php echo Yii::app()->user->id; ?>" name="CatalogItem[user_id]" />
			</div>



			<div class="row" ng-controller="PicturesEditorCtrl" ng-init="init('catalog-item-form', '<?php echo Yii::app()->createAbsoluteUrl("pictures/upload"); ?>', '<?php echo Yii::app()->request->baseUrl; ?>/', '<?php echo CHtml::encode(CJSON::encode($model->pictures)); ?>')">
				<?php echo $form->labelEx($model,'image'); ?>
				<div class="large-3 columns button secondary [radius round]">
				Select Image
				<input class=" " type="file" name="file" id="file" on-change="uploadPicture" />
			</div>
				<div id="uploads" >
					<ul class="clearing-thumbs no-bullet" data-clearing>
						<li class="" ng-repeat="picture in pictures">
							<div class="fi-x-circle right" ng-click="deletePicture(picture)"></div>
							<a class="th" ng-href="{{picture.url}}">
								<img width="100px" ng-src="{{picture.url}}" />
								<input type="hidden" name="pictures[]" ng-value="picture.url" />
							</a>
						</li>
					</ul>
				</div>
			</div>

			<div class="row buttons">
				<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save', array('class'=>'medium button [secondary radius round]')); ?>
			</div>

		<?php $this->endWidget(); ?>

	</div><!-- form -->


<script src="<?php echo Yii::app()->request->baseUrl; ?>/assets/js/PicturesEditorController.js"></script>